package com.xinhe.web.controller;

import com.xinhe.web.common.Result;
import com.xinhe.web.service.UserService;
import com.xinhe.web.session.UserSessionManager;
import com.xinhe.web.session.UserSessionView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashSet;

@Api(value = "用户标识", tags = {"用户标识"})
@RestController
@RequestMapping(value = {"/user"}, produces = {"application/json;charset=UTF-8"})
public class UserController
{
    @Autowired
    private UserSessionManager userSessionManager;
    @Autowired
    private UserService userService;

    @ApiOperation(value = "校验用户登录", httpMethod = "GET")
    @RequestMapping({"/validToken"})
    public Result validToken() {
        Boolean valid = this.userSessionManager.validToken();
        if (!valid.booleanValue()) {
            Long userId = this.userSessionManager.getUserId();
            if (null != userId) {
                this.userService.userLogin(userId,new HashSet<>(),null);
            }
        }
        return Result.ok(valid);
    }

    @ApiOperation(value = "查询当前用户角色", httpMethod = "GET")
    @RequestMapping({"/findRole"})
    public Result findRole(Long userId) {
        return this.userService.findRole(userId);
    }

}